﻿using System.Configuration;
using DataAccess;

namespace DataAccess.Common
{
    /// <summary>
    /// DataObjectFactory caches the connectionstring so that the context can be created quickly.
    /// </summary>
    public static class DbConectionFactories
    {
        private static StoreManagementEntities context;
        /// <summary>
        /// Static constructor. Reads the connectionstring from web.config just once.
        /// </summary>
        static DbConectionFactories()
        {

        }

        /// <summary>
        /// Creates the Context using the current connectionstring.
        /// </summary>
        /// <remarks>
        /// Gof pattern: Factory method. 
        /// </remarks>
        /// <returns>Action Entities context.</returns>
        public static StoreManagementEntities CreateContext()
        {
            if (context == null) 
            {
                return new StoreManagementEntities();
            }
            return context;
        }
    }
}
